package 使用线程池;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @作者:侯国威
 * @时间: 2020/4/12/15:30
 * @邮箱:1045077189@qq.com
 */
public class Test {
    public static void main(String[] args) {
       Index index =new Index();

       Thread thread=new Thread(index);
       thread.setName("偶数:");
       Index index1 =new Index();
       Thread thread1=new Thread(index1);
       thread1.setName("奇数:");
       ExecutorService executorService= Executors.newFixedThreadPool(10);
       executorService.execute(index1);
       executorService.execute(index);
       executorService.shutdown();
    }
}
class Index implements Runnable{
    int sum=0;
    @Override
    public void run() {
        for (int i = 0; i<100; i++){
            if (i%2==0){
                sum+=i;
                System.out.println(Thread.currentThread().getName()+":"+i);
            }

        }
        System.out.println(Thread.currentThread().getName()+":"+sum);
    }
}